<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>登陆</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
	<link href="css/style.css" rel="stylesheet">
	<link href="bootstrap/css/bootstrap1.min.css" rel="stylesheet">
	<link href="css/style1.css" rel="stylesheet">

  </head>
  
  <body>
  	<%@include file="common/Top.jsp" %>
    <div class="container">
	<div class="row">
	<div class="span4"></div>
		<div class="span4">
				<div style="height: 60%">
					<table style="margin-top: 100px">
						<tr>
							<td style="text-align: right;">用户名：</td>
							<td><input id="inputUserName" name="username" type="text" value="" style="height: 30px"/></td>
						</tr>
						<tr>
							<td style="text-align: right;">密码：</td>
							<td><input id="inputPassWord" name="password" type="password" value="" style="height: 30px"/></td>
						</tr>
					</table>
					<div align="center"><input type="button" class="btn" value="登陆" onclick="login()"/></div>
				</div>
		</div>
		<div class="span4"></div>
	</div>
</div>
    
    <%@include file="common/Bottom.jsp" %>
    <script src="backadmin/js/jquery-1.10.2.min.js"></script> 
	<script src="bootstrap/js/bootstrap.js"></script>
	<script type="text/javascript">
	$(document).ready(function(){
		var userSession = "<%=session.getAttribute("user")%>"; 
		if(userSession != "null"){
			window.location.href="backadmin";
		}
	});
	function login(){
		var username = '';
		var password = '';
		if($("#inputUserName").val().trim()==null||$("#inputUserName").val().trim()==""){
			alert("请输入用户名");
			return;
		}else{
			username = $("#inputUserName").val().trim();
		}
		if($("#inputPassWord").val()==null||$("#inputPassWord").val()==""){
			alert("请输入密码");
			return;
		}else{
			password = $("#inputPassWord").val();
		}
		$.ajax({
			type:'POST',
			url:'Login.action',
			data:'user.username='+username+'&user.password='+password,
			success:function(data){
				if(data=="\"pass\""){
					showBackByRole(username);
				}else{
					alert("用户名和密码不正确");
					$("#inputUserName").val("");
					$("#inputPassWord").val("");
				}
			}
		});
	}
	function showBackByRole(username){
		//window.location.href="ShowByRole.action?user.username="+username;
		//$.post("ShowByRole.action",
		//		{"user.username":username});
		$.ajax({
			url:'ShowByRole.action',
			data:'user.username='+username,
			success:function(data){
				alert("欢迎你"+username);
				window.location.href="backadmin";
			}
		});
	}
	</script>
  </body>
</html>
